#include "cExecute.h"

#include <stdlib.h>
#include <sstream>
#include <stdio.h>

#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeIterator.h>
#include <Poco/Base64Encoder.h>
#include <Poco/Base64Decoder.h>
#include <Poco/StreamCopier.h>
#include "misc/Interface.h"
#include "misc/Debug.h"
#include "client/Client.h"
/*********************************************************/
void cExecute::execute()
{
	// Clients only sent execute message they don't execute them!
}
/*********************************************************/
std::string cExecute::serialize() const
{
	Client& c = Client::Instance();
	std::ostringstream		xml;
	std::ostringstream		cmdstr;

	// The command needs to be a multiple of 6 bits ( due to base 64 encoding )
	std::string cmd_ = cmd;
	while ( ((cmd_.length()*8) % 6) != 0 ) {
		cmd_.append("\n");
	}

	// Encode the aligned command
	Poco::Base64Encoder	encoder(cmdstr);
	encoder << cmd_;

	id = c.getID();

	// Build the xml string for this job
	xml << "<GS id='" << id << "'>";
	xml << "<Execute>";
	xml << "<cmd>" << cmdstr.str() << "</cmd>";
	xml << "</Execute>";
	xml << "</GS>";

	return( xml.str() );
}
/*********************************************************/
void cExecute::deserialize(Poco::XML::NodeIterator& it)
{
	// Clients only sent execute message! so we do nothing here
}
/*********************************************************/
std::string cExecute::getCommand() const
{
	return( cmd );
}
/*********************************************************/
void cExecute::setCommand(std::string cmd)
{
	cExecute::cmd = cmd;
}
